//
//  ViewController.m
//  SZBank
//
//  Created by LuoYao on 16/7/8.
//  Copyright © 2016年 LuoYao. All rights reserved.
//

#import "ViewController.h"
#import "LYLoginView.h"
#import "LUOYAOTestViewController.h"
#import "UserManagerView.h"
#import "WDDFinancialView.h"
#import "LYMyBankView.h"
#import "BJInvestmentView.h"
#import "WDDBankBusinessView.h"
#import "BankMap.h"
#import "BJCitizenCard.h"
#import "LYCommonProducView.h"


@interface ViewController ()
{
    NSInteger _index;/**< 上次选中的页面 */
}
@property (nonatomic) LYLoginView *loginView;/**< 登录界面 */
@property (nonatomic) UIImageView *backImageview;/**< 背景图片 */
@property (nonatomic) UIImageView *selectRowImage;/**< 选中的图片指示 */


@property (nonatomic) WDDFinancialView *wddFinancia;/**< 金融资讯 */
@property (nonatomic) WDDBankBusinessView *wddBankBusiness;/**< 银行业务 */
@property (nonatomic) BJInvestmentView *bjInvestment;/**< 投资理财 */
@property (nonatomic) BJCitizenCard *bjCitizenCard;/**< 市民卡 */
@property (nonatomic) LYCommonProducView *lycommonView;/**< 对公产品 */
@property (nonatomic) BankMap *bankMap;/**< 网点地图 */
@property (nonatomic) LYMyBankView *lyMyBank;/**< 我的银行 */

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    

    
    //背景图片
    [self.view addSubview:self.backImageview];
    
    
    //头部视图
    UserManagerView *topView = [[UserManagerView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT * 0.1)];
    [self.view addSubview:topView];
    
    
    //左边视图
    NSArray *leftMenu = @[@"金融资讯",@"银行业务",@"投资理财",@"市民卡",@"对公产品",@"网点地图",@"我的银行"];
    
    for (int i = 0; i < leftMenu.count; i ++) {
        UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(KWIDTH * 0.01, i * KHEIGHT / 8 + KHEIGHT / 9, KHEIGHT / 8, KHEIGHT / 8)];
        btn.tag = 1000 + i;
        [btn setImage:[LocalDataManager getImageWithSourceOfPath:leftMenu[i]] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(action_leftBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:btn];
    }
    
    //选中按钮图片
    [self.view addSubview:self.selectRowImage];
    
    
    //默认页面金融资讯
    WDDFinancialView *vc = [[WDDFinancialView alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    [self.view addSubview:vc];
    
    //登录
    [self.view addSubview:self.loginView];
    
    
    //注销通知加载登录界面
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(action_notification) name:@"loginout" object:nil];
}
#pragma mark - 移除通知
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - 通知方法加载登录界面
- (void)action_notification{
    [self.view addSubview:self.loginView];
}

#pragma mark - action_leftBtnClick
- (void)action_leftBtnClick:(UIButton *)sender{
    
    if (_index == sender.tag - 1000) {
        return;
    }
    
    //移除多余视图
    for (int i = 10; i < self.view.subviews.count; i ++) {
        [self.view.subviews[i] removeFromSuperview];
    }
    //指示器位置移动
    [self selectImageAnimation:sender.tag - 1000];
    
    switch (sender.tag - 1000) {
        case 0:
        {
            [self.view addSubview:self.wddFinancia];
        }
            break;
        case 1:
        {
            [self.view addSubview:self.wddBankBusiness];
        }
            break;
        case 2:
        {
            [self.view addSubview:self.bjInvestment];
            break;
        }
            
            case 3:
        {
            [self.view addSubview:self.bjCitizenCard];
        }
            break;
        case 4:
        {
            [self.view addSubview:self.lycommonView];
        }
            break;
        case 5:
        {
            [self.view addSubview:self.bankMap];
        }
            break;
            
        case 6:
        {
            [self.view addSubview:self.lyMyBank];
        }
            break;
        default:
            break;
    }
    
    _index = sender.tag - 1000;
}

#pragma mark - 选中指示图片位置移动方法
- (void)selectImageAnimation:(NSInteger)index{
    [UIView animateWithDuration:0.25 animations:^{
       self.selectRowImage.center = CGPointMake(KWIDTH * 0.115, self.view.subviews[index + 2].center.y);
    }];
}

#pragma mark - 测试toubegan
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
}


#pragma mark - getter
- (LYLoginView *)loginView{
    if (!_loginView) {
        _loginView = [[LYLoginView alloc] initWithFrame:self.view.bounds];
    }
    return _loginView;
}


- (UIImageView *)backImageview{
    if (!_backImageview) {
        _backImageview = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _backImageview.image = [LocalDataManager getImageWithSourceOfPath:@"大背景"];
        _backImageview.userInteractionEnabled = YES;
    }
    return _backImageview;
}

- (UIImageView *)selectRowImage{
    if (!_selectRowImage) {
        _selectRowImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 22, 34)];
        [_selectRowImage setImage:[LocalDataManager getImageWithSourceOfPath:@"选中指示三角"]];
        _selectRowImage.center = CGPointMake(KWIDTH * 0.115, self.view.subviews[2].center.y);
    }
    return _selectRowImage;
}


- (WDDFinancialView *)wddFinancia{
    if (!_wddFinancia) {
        _wddFinancia = [[WDDFinancialView alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _wddFinancia;
}

- (WDDBankBusinessView *)wddBankBusiness{
    if (!_wddBankBusiness) {
        _wddBankBusiness = [[WDDBankBusinessView alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _wddBankBusiness;
}

- (BJInvestmentView *)bjInvestment{
    if (!_bjInvestment) {
        _bjInvestment = [[BJInvestmentView alloc]initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _bjInvestment;
}

- (BankMap *)bankMap{
    if (!_bankMap) {
        _bankMap = [[BankMap alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _bankMap;
}

- (LYMyBankView *)lyMyBank{
    if (!_lyMyBank) {
        _lyMyBank = [[LYMyBankView alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _lyMyBank;
}

- (BJCitizenCard *)bjCitizenCard{
    if (!_bjCitizenCard) {
        _bjCitizenCard = [[BJCitizenCard alloc]initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _bjCitizenCard;
}

- (LYCommonProducView *)lycommonView{
    if (!_lycommonView) {
        _lycommonView = [[LYCommonProducView alloc] initWithFrame:CGRectMake(KWIDTH * 0.12, KHEIGHT / 9, KWIDTH * 0.88, KHEIGHT * 0.9)];
    }
    return _lycommonView;
}
@end
